package com.diy.sigmund.diycommon.designpatterns.observer;

import java.util.StringJoiner;

/**
 * @author ylm-sigmund
 * @since 2022/1/14 15:17
 */
public class CurrentConditionsDisplay implements Observer, DisplayElement {

    private float temperature;
    private float humidity;
    private Subject weatherData;

    public CurrentConditionsDisplay(Subject weatherData) {
        this.weatherData = weatherData;
        weatherData.registerObserver(this);
    }

    @Override
    public void display() {
        String s = new StringJoiner(", ", CurrentConditionsDisplay.class.getSimpleName() + "[", "]")
                .add("temperature=" + temperature)
                .add("humidity=" + humidity)
                .toString();
        System.out.println(s);
    }

    @Override
    public void update(float temperature, float humidity, float pressure) {
        this.temperature = temperature;
        this.humidity = humidity;
        display();
    }
}
